export const setTMToken = (userID: string, token: string) => {
  localStorage.setItem(`IM_TOKEN_${userID}`, token)
}

export const setTMUserID = (userID: string) => {
  localStorage.setItem(`IM_USERID`, userID)
}

export const setIMProfile = ({ imToken, userID, friendID }: any) => {
  setTMToken(userID, imToken)
  setTMUserID(userID)
}

export const clearIMProfile = () => {
  localStorage.clear()
}

export const getIMToken = () => {
  const userID = localStorage.getItem('IM_USERID')
  return localStorage.getItem(`IM_TOKEN_${userID}`)
}
export const getIMUserID = () => {
  return localStorage.getItem('IM_USERID')
}
export const getTMFriendID = () => {
  return ''
}

export const getAccessedFriendApplication = () =>
  localStorage.getItem(`${getIMUserID()}_accessedFriendApplications`)
    ? JSON.parse(localStorage.getItem(`${getIMUserID()}_accessedFriendApplications`)!)
    : []
export const getAccessedGroupApplication = () =>
  localStorage.getItem(`${getIMUserID()}_accessedGroupApplications`)
    ? JSON.parse(localStorage.getItem(`${getIMUserID()}_accessedGroupApplications`)!)
    : []

export const getWsUrl = () => localStorage.getItem('wsUrl') || process.env.WS_URL!
export const getApiUrl = () => localStorage.getItem('apiUrl') || process.env.API_URL!
export const getChatUrl = () => localStorage.getItem('chatUrl') || process.env.CHAT_URL!
export const getLogLevel = () =>
  localStorage.getItem('logLevel') || process.env.LOG_LEVEL!
